package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.UserDto;
import com.zzyl.entity.Dept;
import com.zzyl.entity.Role;
import com.zzyl.entity.User;
import com.zzyl.enums.BasicEnum;
import com.zzyl.exception.BaseException;
import com.zzyl.mapper.UserMapper;
import com.zzyl.service.UserService;
import com.zzyl.utils.NoProcessing;
import com.zzyl.vo.RoleVo;
import com.zzyl.vo.UserVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;



    @Override
    public PageResponse<UserVo> finduserPage(UserDto userDto, int pageNum, int pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        Page<User> userPage = userMapper.seletePage(userDto);
        PageResponse<UserVo> pageResponse = PageResponse.of(userPage, UserVo.class);

        log.info("分页后的数据：{}", pageResponse);

        return pageResponse;
    }

    @Override
    public Boolean AddUser(UserDto userDto) {
        User user = BeanUtil.toBean(userDto, User.class);
        log.info("业务层增加的数据:{}",user);

    Boolean flag1  =  userMapper.addUser(user);



        return flag1;
    }

    @Override
    public void deleteUseById(String userIds) {

        userMapper.deleteUseById(userIds);
    }


 @Override
    public void isEnuser(Long id, String status) {

    User user =   userMapper.selectByPrimaryKey(id);

    user.setDataState(status);
   userMapper.updateByPrimaryKeySelective(user);
    }




}



/*log.info("业务层分页的数据:{}",pageResponse);

        return pageResponse;*/
  //  }

